/*************************************************************
 * File: Privilege.java
 * Copyright (c) 2012
 * Author: Huang Shaobin
 * Email: Shaobin.Software@gmail.com Shaobin_Software@163.com 
 * Date: Feb 20, 2013
 * Description: 
 ************************************************************/

package snow.biz.security.model;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.builder.HashCodeBuilder;

import snow.biz.basic.model.Persistence;
import snow.biz.system.model.User;
import snow.core.enums.Status;
import snow.core.exceptions.BusinessException;
import snow.core.security.Operator;
import snow.core.security.Permission;

/**
 * 权限信息
 * 
 * @author Shaobin.Software@gmail.com Shaobin_Software@163.com
 * @version 1.0
 */
@SuppressWarnings("serial")
public class Privilege extends Persistence<Integer> implements Permission {
	
	public static Boolean NEED_CHECK = Boolean.TRUE;
	public static Boolean NOT_NEED_CHECK = Boolean.FALSE;

	private String uri; // 所属资源
	private String name; // 权限名称
	private Operator type; // 操作类型
	private String comment; // 权限描述
	private Boolean needCheck; // 是否需要

	protected Privilege() {
	}

	public Privilege(User createUser, Status status, String uri, Operator type, String name, String comment, Boolean needCheck) throws BusinessException {
		super(createUser, status);
		setUri(uri);
		setType(type);
		setName(name);
		setComment(comment);
		setNeedCheck(needCheck);
	}

	public boolean equals(Object obj) {
		if (obj instanceof Privilege) {
			final Privilege privilege = (Privilege) obj;
			return ObjectUtils.equals(getUri(), privilege.getUri()) && ObjectUtils.equals(getType(), privilege.getType());
		}
		return super.equals(obj);
	}

	public String getComment() {
		return this.comment;
	}

	public String getName() {
		return this.name;
	}

	public Operator getType() {
		return this.type;
	}

	public String getUri() {
		return this.uri;
	}

	public int hashCode() {
		return new HashCodeBuilder().append(getUri()).append(getType()).toHashCode();
	}

	public boolean isNeedCheck() {
		return this.needCheck == null ? true : this.needCheck.booleanValue();
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setNeedCheck(boolean needCheck) {
		this.needCheck = Boolean.valueOf(needCheck);
	}

	public void setType(Operator type) {
		this.type = type;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

}
